package com.wc.alorithm_blue_bridge._字符串.KMP.Q1203;

import java.util.*;

/**
 * @Author congege
 * @Description 小明的字符串
 * https://www.lanqiao.cn/problems/1203/learning/?page=1&first_category_id=1
 * @Date Created in 2023/12/1-10:23
 */
public class Main {
    static int ans = 0;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        String sub = scan.nextLine();
        kmp(str, sub, 0);
        System.out.println(ans);
        scan.close();
    }

    private static int kmp(String str, String sub, int pos) {
        int lenStr = str.length();
        int lenSub = sub.length();

        int i = pos;
        int j = 0;
        int[] next = new int[lenSub];
        int[] nextVal = new int[lenSub];

        getNext(sub, next);
        getNextVal(sub, next, nextVal);

        while (i < lenStr && j < lenSub) {
            if (j == -1 || str.charAt(i) == sub.charAt(j)) {
                i++;
                j++;
            } else {
                ans = Math.max(j, ans);
                j = nextVal[j];
            }
        }
        if (j >= lenSub) {
            ans = Math.max(j, ans);
            return i - j;
        }
        return -1;
    }

    private static void getNext(String sub, int[] next) {
        next[0] = -1;
        int lenSub = sub.length();
        if (lenSub < 2) {
            return;
        }
        next[1] = 0;
        int i = 2;
        int k;
        while (i < lenSub) {
            k = next[i - 1];
            while (k != -1 && sub.charAt(i - 1) != sub.charAt(k)) {
                k = next[k];
            }
            next[i] = k + 1;
            i++;
        }
    }

    private static void getNextVal(String sub, int[] next, int[] nextVal) {
        nextVal[0] = next[0];
        int lenSub = sub.length();
        int i = 1;
        while (i < lenSub) {
            if (sub.charAt(i) == sub.charAt(next[i])) {
                nextVal[i] = nextVal[next[i]];
            } else {
                nextVal[i] = next[i];
            }
            i++;
        }
    }
}
